home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Bookmark.subproj / eTBookmarkUI.m < prev    next >
Encoding:
Text File  |  1994-12-07  |  3.9 KB  |  169 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTBookmarkUI.m
  3. //    SUMMARY:    Implementation of the inspector of Bookmarks
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    eTBookmarkUI.nib
  6. //    PROTOCOLS:    <Inspectable>
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //  IMPLEMENTATION COMMENTS
  11. //        You name it.
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //    HISTORY
  14. //    11/13/94:    Modified to use a storage for sorted bookmark lists.
  15. //    05/08/94:    Created. First actual implementation.
  16. ///////////////////////////////////////////////////////////////////////////////
  17.  
  18. #import "eTBookmarkUI.h"
  19. #define PROP "Anchor Properties"
  20.  
  21. @implementation eTBookmarkUI
  22. //    id    contentPanel;
  23. //    id    contentView;
  24. //    id    theBookmark;
  25. //    long docID;
  26.  
  27. + new
  28. {
  29.     static eTBookmarkUI *ui = nil;
  30.     
  31.     if (!ui) {
  32.         ui = [[eTBookmarkUI alloc] init];
  33.     }
  34.     return ui;
  35. }
  36.  
  37. - init
  38. {
  39.     char        buf[MAXPATHLEN];
  40.     NXBundle   *bundle;
  41.  
  42.     [super init];
  43.     bundle = [NXBundle bundleForClass:[eTBookmarkUI class]];
  44.     if ( [bundle getPath:buf forResource:"eTBookmarkUI" ofType:"nib"] ) {
  45.         [NXApp loadNibFile:buf owner:self withNames:NO];
  46.     } else {
  47.         NXLogError("NIB not found: eTBookmarkUI");
  48.     }
  49.     contentView = [contentPanel contentView];
  50.     bmStore = [[Storage alloc] init];
  51.     return self;
  52. }
  53. - free {return self;}
  54.  
  55. - setBookmark:newBookmark inDoc:(long)newDocID
  56. {
  57.     if ((theBookmark != newBookmark) || 
  58.         (docID != newDocID) || 
  59.         ([[eTBookmarkBinder new] isDirty])){
  60.         theBookmark = newBookmark;
  61.         docID = newDocID;
  62.         [self load];
  63.     }
  64.     return self;
  65. }
  66.  
  67. - load
  68. {
  69.     char idstr[32];
  70.     
  71.     sprintf(idstr, "%x", [theBookmark id]);
  72.     [idField setStringValue:NXUniqueString(idstr)];
  73.     [titleField setStringValue:[theBookmark title]];    
  74.     [conditionField setStringValue:[theBookmark condition]];
  75.     [bmStore empty];
  76.     [[eTBookmarkBinder new] getBookmarks:bmStore inDoc:docID];
  77.     [browser loadColumnZero];
  78.     [browser setPath:[theBookmark title]];    
  79.     return self;
  80. }
  81.  
  82. //////////////////////
  83. - (const NXAtom *) types
  84. {
  85.     static NXAtom types[2] = {NULL, NULL};
  86.     
  87.     if (!types[0]) {
  88.         types[0] = NXUniqueString(PROP);
  89.     }
  90.     return types;
  91. }
  92.  
  93. - (const char *) inspectorTitle
  94. {
  95.     return NXUniqueString("Bookmark");
  96. }
  97.  
  98. - resignInspector: (View *) oldInspector ofType: (const char *) type
  99. {
  100.     return self;
  101. }
  102.  
  103. - activateInspector: (View *) newInspector ofType: (const char *) type
  104. {
  105.     [[NXApp inspector] makeFirstResponder:browser];
  106.     return self;
  107. }
  108.  
  109. - inspectorForType:(const char *) type
  110. {
  111.     if(!strcmp(type,NXUniqueString(PROP)))
  112.         return contentView;
  113.     NXLogError("Massive Inspector Failure: Asked eTBookmarkUI for: %s", type);
  114.     return contentView;
  115. }
  116.  
  117. ///////////////////////////////
  118.  
  119. - resetTitle:sender
  120. {
  121.     [theBookmark setTitle:[sender stringValue]];
  122.     [self load];
  123.     return self;
  124. }
  125.  
  126. - resetCondition:sender
  127. {
  128.     [theBookmark setCondition:[sender stringValue]];
  129.     [self load];
  130.     return self;
  131. }
  132.  
  133. static int eTBookmarkUI_docompare(eTBookmark **x, eTBookmark **y)
  134. {
  135.     return strcasecmp([*(eTBookmark **)x title],[*(eTBookmark **)y title]);
  136. }
  137.  
  138. - (int) browser:theBrowser fillMatrix:theMatrix inColumn:(int) col 
  139. {
  140.     int        rows,i;
  141.     id        cell;
  142.     
  143.     rows = [bmStore count];
  144.     qsort(bmStore->dataPtr,bmStore->numElements,bmStore->elementSize,eTBookmarkUI_docompare);
  145.     for (i=0; i <rows; i++) {
  146.         [theMatrix addRow];
  147.         cell = [theMatrix cellAt:i :0];
  148.         [cell setStringValueNoCopy:[*(eTBookmark **)[bmStore elementAt:i] title]];
  149.         [cell setLoaded:YES];
  150.         [cell setLeaf:YES];
  151.     }
  152.     return rows;
  153. }
  154.  
  155. - selectBookmark2:sender
  156. {
  157.     theBookmark = *(eTBookmark **)[bmStore elementAt:[[browser matrixInColumn:0] selectedRow]];
  158.     // highlight the new bookmark
  159.     [theBookmark highlight:self];
  160.     // inspect the new bookmark
  161.     [self load];
  162.     return sender;
  163. }
  164. - selectBookmark:sender
  165. {
  166.     [self perform:@selector(selectBookmark2:) with:sender afterDelay:0 cancelPrevious:YES];
  167.     return self;
  168. }
  169. @end